package com.example.design.shejimoshi.structure.flyweight.demo01;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description TODO
 * @date 2022/10/25 15:52
 * @Author liuzhihui
 * @Version 1.0
 */
public class ChessPieceUnitFactory {
    // key棋子id, value享元类
    private static final Map<Integer,ChessPieceUnit> pieces = new HashMap<Integer,ChessPieceUnit>(){
        {
            put(1, new ChessPieceUnit(1, "車", ChessPieceUnit.Color.BLACK));
            put(2, new ChessPieceUnit(2, "馬", ChessPieceUnit.Color.RED));
            // ....
        }
    };

    public static ChessPieceUnit getChessPieceUnit(int chessPieceId) {
        return pieces.get(chessPieceId);
    }
}
